/**********************************************************************
*  Copyright (c) 2007 - Victor Jacobs - victor.jacobs@gmail.com
*
*  Permission is hereby granted, free of charge, to any person
*  obtaining a copy of this software and associated documentation
*  files (the "Software"), to deal in the Software without
*  restriction, including without limitation the rights to use,
*  copy, modify, merge, publish, distribute, sublicense, and/or sell
*  copies of the Software, and to permit persons to whom the
*  Software is furnished to do so, subject to the following
*  conditions:
*
*  The above copyright notice and this permission notice shall be
*  included in all copies or substantial portions of the Software.
*
*  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
*  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
*  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
*  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
*  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
*  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
*  OTHER DEALINGS IN THE SOFTWARE.
**********************************************************************/

using System;
using System.Collections.Generic;
using System.Text;

namespace Vj.Ann
{
    public class PatternBuilder
    {

        public static List<Pattern> NANDPattern()
        {
            List<Pattern> patterns = new List<Pattern>();

            patterns.Add(new Pattern(2, 1));
            patterns[0].Inputs = new double[] { 1.0, 1.0 };
            patterns[0].Outputs = new double[] { 0.0 };

            patterns.Add(new Pattern(2, 1));
            patterns[1].Inputs = new double[] { 0.0, 0.0 };
            patterns[1].Outputs = new double[] { 1.0 };

            patterns.Add(new Pattern(2, 1));
            patterns[2].Inputs = new double[] { 0.0, 1.0 };
            patterns[2].Outputs = new double[] { 1.0 };

            patterns.Add(new Pattern(2, 1));
            patterns[3].Inputs = new double[] { 1.0, 0.0 };
            patterns[3].Outputs = new double[] { 1.0 };

            return patterns;
        }

        public static List<Pattern> XORPattern()
        {
            List<Pattern> patterns = new List<Pattern>();

            patterns.Add(new Pattern(2, 1));
            patterns[0].Inputs = new double[] { 1.0, 1.0 };
            patterns[0].Outputs = new double[] { 0.0 };

            patterns.Add(new Pattern(2, 1));
            patterns[1].Inputs = new double[] { 0.0, 0.0 };
            patterns[1].Outputs = new double[] { 0.0 };

            patterns.Add(new Pattern(2, 1));
            patterns[2].Inputs = new double[] { 0.0, 1.0 };
            patterns[2].Outputs = new double[] { 1.0 };

            patterns.Add(new Pattern(2, 1));
            patterns[3].Inputs = new double[] { 1.0, 0.0 };
            patterns[3].Outputs = new double[] { 1.0 };

            return patterns;
        }

        public static List<Pattern> ONESPattern(int length, int numOfPatterns)
        {
            List<Pattern> patterns = new List<Pattern>();
            Random randGen = new Random();

            double sum = 0;

            for (int i = 0; i < numOfPatterns; i++)
            {
                patterns.Add(new Pattern(length, 1));

                double[] list = new double[length];

                sum = 0;

                for (int j = 0; j < length; j++)
                {
                    list[j] = (double)randGen.Next(2);

                    if (list[j] == 1.0)
                        sum++;
                }

                patterns[i].Inputs = list;
                patterns[i].Outputs = new double[] { sum / (double)length };
            }

            return patterns;
        }

    }
}
